#include "stm32l0xx_hal.h"

#define POLYNOMIAL 0xEDB88320

uint32_t crc32(uint8_t* data, uint32_t len)
{
    uint8_t bit;
    uint32_t crc = 0xffffffff;
    uint32_t i;

    for (i=0; i<len; i++) {
        crc ^= ((uint32_t)data[i]) << 24;

        for (bit=0; bit<8; bit++) {
            if (crc & 0x80000000) crc = (crc << 1) ^ POLYNOMIAL;
            else crc = (crc << 1);
        }
    }

    return crc;
}
